package com.wyh.rabbitextensionsdemo.config;

import com.wyh.rabbitextensionsdemo.constant.Constants;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DelayConfig {
    @Bean("delayQueue")
    public Queue delayQueue(){
        return QueueBuilder.durable(Constants.DELAY_QUEUE).build();
    }

    @Bean("delayExchange")
    public DirectExchange delayExchange(){
        return ExchangeBuilder.directExchange(Constants.DELAY_EXCHANGE)
                .delayed().durable(true).build();
    }

    @Bean("delayQueueBinding")
    public Binding delayQueueBinding(@Qualifier("delayExchange") DirectExchange exchange,
                                    @Qualifier("delayQueue") Queue queue){
        return BindingBuilder.bind(queue).to(exchange).with(Constants.DELAY_ROUTING_KEY);
    }

}
